package com.example.springboot.service;

import com.example.springboot.entity.Earnings;
import com.example.springboot.mapper.EarningsMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class EarningsService {
    @Resource
    private EarningsMapper earningsMapper;

    public List<Earnings> getEarningsByMerchantId(int merchantId) {
        return earningsMapper.findByMerchantId(merchantId);
    }

    public List<Earnings> getEarningsByAdminId(int adminId) {
        return earningsMapper.findByAdminId(adminId);
    }


    public List<Earnings> getAllEarnings() {
        return earningsMapper.findAll();
    }

    public BigDecimal getTotalEarningsByMerchantId(int merchantId) {
        return earningsMapper.getTotalEarningsByMerchantId(merchantId);
    }

    public BigDecimal getTotalPlatformEarnings() {
        return earningsMapper.getTotalPlatformEarnings();
    }

    public BigDecimal getTotalMerchantEarnings() {
        return earningsMapper.getTotalMerchantEarnings();
    }
    // 新增方法
    public PageInfo<Earnings> getEarningsByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Earnings> earnings = earningsMapper.findAll();
        return new PageInfo<>(earnings);
    }

    public List<Earnings> filterEarnings(Date startTime, Date endTime, String orderType) {
        return earningsMapper.findByConditions(startTime, endTime, orderType);
    }

    public BigDecimal getPlatformTotalByDateRange(Date start, Date end) {
        return earningsMapper.getTotalPlatformEarningsByDateRange(start, end);
    }

    public BigDecimal getTotalEarningsByAdmin(int adminId) {
        return earningsMapper.getTotalEarningsByAdminId(adminId);
    }

    public BigDecimal getSelfServiceEarningsByAdmin(int adminId) {
        return earningsMapper.getSelfServiceEarningsByAdminId(adminId);
    }
    public BigDecimal getPlatformTotalByAdmin(int adminId) {
        return earningsMapper.getPlatformTotalByAdminId(adminId);
    }
    public BigDecimal getMerchantTotalByAdmin(int adminId) {
        return earningsMapper.getMerchantTotalByAdminId(adminId);
    }

}
